package airthmetic.exercise.linkedList;

public class _剑指Offer22_链表中倒数第k个节点 {
     public ListNode getKthFromEnd(ListNode head, int k) {
        if(head == null){
            return head;
        }
        ListNode fastNode = head;
        ListNode slowNode = head;

        while(k-- > 0){
            fastNode = fastNode.next;
        }

        while(fastNode !=null){
            fastNode = fastNode.next;
            slowNode = slowNode.next;
        }

        return slowNode;
    }
}
